package com.chenxi.vhr.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.chenxi.vhr.bean.BaseDepartment;
import com.chenxi.vhr.bean.vo.DepartmentTreeVo;
import com.chenxi.vhr.mapper.BaseDepartmentMapper;
import com.chenxi.vhr.service.BaseDepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 *  部门管理 Service
 */
@Service
public class BaseDepartmentServiceImpl extends ServiceImpl<BaseDepartmentMapper, BaseDepartment>
    implements BaseDepartmentService {

    @Autowired
    BaseDepartmentMapper departmentMapper;

    @Override
    public List<DepartmentTreeVo> getDeptTree() {
        // 通过SQL递归查询部门树信息
        return departmentMapper.getChildDeptByParentId(-1);
    }

    @Override
    public void addDept(BaseDepartment department) {
        department.setEnabled(true);
        // 在mapper中调用存储过程
        departmentMapper.addDept(department);
    }

    @Override
    public void deleteDept(BaseDepartment department) {
        departmentMapper.deleteDept(department);
    }
}




